package com.laiyw.monitor.core.context;

import com.laiyw.monitor.core.commons.Constants;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * @Description:
 * @Auther: Laiyw
 * @Date: 2018/10/5 11:38
 */
@WebListener
public class ContextListener extends ContextLoader implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        long beginTime = System.currentTimeMillis();
        logger.info(" - Initializing 'Server Monitor'");
        initServiceBeans(sce.getServletContext());
        logger.info(" - 'Server Monitor' initialization completed in " + (System.currentTimeMillis() - beginTime) + "ms");
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        logger.info(" - Destroyed 'Server Monitor'");
        sce.getServletContext().removeAttribute(Constants.MONITOR_REQUEST_MAP);
    }
}
